using System;

using System.Xml;
using System.Xml.Xsl;

/*	-----------------------------------------------------------------------	
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington	
	Started:	2006-03-08	
	Status:		release	
	Version:	2.0.0
	Build:		20070524
	License:	GNU General Public License
	-----------------------------------------------------------------------	*/
	
/*	-----------------------------------------------------------------------	
	Development Notes:
	==================
	20070524:	Modification for .Net 2.0
	-----------------------------------------------------------------------	*/
	
namespace umlungu.engineX.blogX {
	/// <summary>
	/// umlungu engineX blog page class.
	/// </summary>
	public class registerX : uiX {
		#region Invisible properties
		private string _name, _username, _firstname, _lastname, _email, _telno, _field1, _field2, _field3, _field4;
		#endregion

		#region Visible properties
		#endregion

		#region Constructors/Destructors
		/// <summary>Constructor</summary>
		public registerX() : base("registerX") {
		}
		#endregion

		#region Protected methods
		/// <summary>
		/// Gets registration information and sends the contact email
		/// </summary>
		protected override void _LoadAdditional() {
			loadSubscriber();
			registerSubscriber();
		}
		#endregion

		#region Private methods
		private void registerSubscriber() {
			x_user userx = new x_user(Application);
			try {
				string defgroup = "public";
				string defsecret = "umlungu";
				string defpassw = "password";
				userx.Add(_username, _firstname, _lastname, _email, _telno, defsecret, defpassw, defgroup, _field1, _field2, _field3, _field4);
				Space.AddUser(_name, _username, defgroup);
				userx.AddBlogspace(_name, _username, defgroup, true);
				Debugger.Spoor("registerSubscriber", "firstname", _firstname, "lastname", _lastname);
			}
			catch(x_exception e) {
				Debugger.Spoor("registerSubscriber", "Code", e.Code, "Message", e.Message);
				if (e.Code == "error_exists") {
					throw(new x_glitch(this, e.Code, e.Message));
				} else {
					throw(e);
				}
			}
		}
		private void loadSubscriber() {
			_name = (Request.Form["Space"] == null)? Name: Request.Form["Space"];
			_username = (Request.Form["Email"] == null)? "anonymous": Request.Form["Email"];
			_firstname = (Request.Form["FirstName"] == null)? "[FirstName]": Request.Form["FirstName"];
			_lastname = (Request.Form["LastName"] == null)? "[LastName]": Request.Form["LastName"];
			_email = (Request.Form["Email"] == null)? "[Email]": Request.Form["Email"];
			_telno = (Request.Form["Phone"] == null)? "[Phone]": Request.Form["Phone"];
			_field1 = (Request.Form["Field1"] == null)? "-": Request.Form["Field1"];
			_field2 = (Request.Form["Field2"] == null)? "-": Request.Form["Field2"];
			_field3 = (Request.Form["Field3"] == null)? "": Request.Form["Field3"];
			_field4 = (Request.Form["Field4"] == null)? "": Request.Form["Field4"];
		}
		#endregion
	}
}
